import { PrismaClient } from "@prisma/client";
import bcrypt from "bcryptjs";

const prisma = new PrismaClient();

async function main() {
  try {
    // 创建默认管理员账号
    const adminPassword = await bcrypt.hash("admin123", 12);
    const admin = await prisma.user.upsert({
      where: { email: "admin@example.com" },
      update: {},
      create: {
        email: "admin@example.com",
        name: "Admin",
        password: adminPassword,
        role: "ADMIN",
      },
    });

    // 创建示例教师账号
    const teacherPassword = await bcrypt.hash("teacher123", 12);
    const teacher = await prisma.user.upsert({
      where: { email: "teacher@example.com" },
      update: {},
      create: {
        email: "teacher@example.com",
        name: "Teacher",
        password: teacherPassword,
        role: "TEACHER",
      },
    });

    // 创建示例学生账号
    const studentPassword = await bcrypt.hash("student123", 12);
    const student = await prisma.user.upsert({
      where: { email: "student@example.com" },
      update: {},
      create: {
        email: "student@example.com",
        name: "Student",
        password: studentPassword,
        role: "STUDENT",
      },
    });

    console.log('Seed data created successfully:');
    console.log({ admin, teacher, student });
  } catch (error) {
    console.error('Error creating seed data:', error);
    throw error;
  }
}

main()
  .then(async () => {
    await prisma.$disconnect();
  })
  .catch(async (e) => {
    console.error(e);
    await prisma.$disconnect();
    process.exit(1);
  }); 